//package com.booter.producer.config;
//
//import com.mongodb.MongoClientURI;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.mongodb.MongoDbFactory;
//import org.springframework.data.mongodb.MongoTransactionManager;
//import org.springframework.data.mongodb.core.MongoTemplate;
//import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
//import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
//import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
//import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
//import org.springframework.data.mongodb.gridfs.GridFsTemplate;
//
//import java.net.UnknownHostException;
//
//@Configuration
//public class MongoConfig {
//
//	@Value("${spring.data.mongodb.uri}")
//	private String mongoUri;
//
//	@Autowired
//	private ApplicationContext context;
//
//	@Bean
//	@Primary
//	public MongoDbFactory factory() throws UnknownHostException {
//		return new SimpleMongoDbFactory(new MongoClientURI(this.mongoUri));
//	}
//
//	@Bean(name = "mongoTemplate")
//	@Primary
//	public MongoTemplate  mongoTemplate(@Qualifier("factory") MongoDbFactory factory) {
//		return new MongoTemplate(factory);
//	}
//
//	@Bean
//	public MappingMongoConverter converter(@Qualifier("factory") MongoDbFactory factory){
//		MongoMappingContext mongoMappingContext = new MongoMappingContext();
//		mongoMappingContext.setApplicationContext(this.context);
//		MappingMongoConverter converter = new MappingMongoConverter(
//				new DefaultDbRefResolver(factory), mongoMappingContext);
//		//去除 _class 属性
//		//converter.setTypeMapper(new DefaultMongoTypeMapper(null));
//		return  converter;
//	}
//
//
//	@Bean
//	public GridFsTemplate gridFsTemplate(@Qualifier("factory") MongoDbFactory factory ,
//										 @Qualifier("converter") MappingMongoConverter converter) {
//		return new GridFsTemplate(factory, converter);
//	}
//
//	@Bean("mongoTx")
//	public MongoTransactionManager transactionManager(MongoDbFactory factory) {
//		return new MongoTransactionManager(factory);
//	}
//
//
//}